package test;


import utilities.TextureDecoder;
import javax.swing.*;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
import java.util.Hashtable;

public class TexLoad_test {

   public static void main(String[] aa){
       okno a = new okno();
   }

}

class okno extends JFrame{
      Image II;
    //BufferedImage bbb;
     okno(){
        utilities.Image tex = TextureDecoder.LoadImage("src/test/demo_tex/0.png");

        byte [] r = new byte[256];
        byte [] g = new byte[256];
        byte [] b = new byte[256];
        byte [] a = new byte[256];
        for (int i = 0; i < 256; i++){
            r[i] = b[i] = g[i] = a[i] = (byte)i;
        }
        IndexColorModel cm = new IndexColorModel(8, 256 , r,g,b,a);
        byte[] arr = new byte[tex.data.capacity()];
        System.err.println("Got " + tex.data.capacity() + "cap");
        tex.data.get(arr);
        // int [] arr2 = new int[tex.data.capacity()];
        // for (int i = 0; i < tex.data.capacity(); i++)
        //     arr2[i] = (int) arr[i];
        // DataBuffer buf = new DataBufferInt(arr2, arr.length);
        // SampleModel sm = getColorModel().createCompatibleSampleModel(tex.width, tex.height);
       //  WritableRaster ras = Raster.createWritableRaster(sm, buf, null);
       // bbb =new BufferedImage(cm, ras, false, null);
        MemoryImageSource mem = new MemoryImageSource(tex.width,tex.height, cm, arr ,0, tex.width);
        II = Toolkit.getDefaultToolkit().createImage(mem);
        ImageIcon ic = new ImageIcon(II);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(ic.getIconWidth(),ic.getIconHeight());
        setVisible(true);
     }

    public void paint(Graphics g)
{
    g.drawImage(II,0,0,this);
}
}